package com.shengdacar.carinsurelib;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.ocr_ui.CameraActivity;
import com.example.ocr_ui.bean.PictureInfo;
import com.example.ocr_ui.util.FormatUtil;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_open).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentSelect = new Intent(MainActivity.this, CameraActivity.class);
                intentSelect.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
                        getExternalFilesDir("crop").getAbsolutePath());
                startActivityForResult(intentSelect,1001);
            }
        });
        findViewById(R.id.btn_share).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(data == null){
            return;
        }
        if(resultCode == RESULT_OK){
            PictureInfo pictureInfo = data.getParcelableExtra(com.example.ocr_ui.CameraActivity.KEY_CONTENT_BEAN);
            if (pictureInfo == null) {
                pictureInfo = new PictureInfo();
            }
            ImageView iv_show = findViewById(R.id.iv_show);
            iv_show.setImageBitmap(BitmapFactory.decodeFile(pictureInfo.getCompressPath()));
            Log.e("图片识别文件大小", FormatUtil.sizeFormatNum2String(new File(pictureInfo.getCompressPath()).length()));
        }
    }
}